import {getQuery, object_w, query_options} from "../../utils/databaseUtil";

export async function get_shop_detail_by_name(name) {
    var query = getQuery('shop')
    query = query_options(query, ['name', '==', name])
    query.include('user')
    var result = await query.first().then(res => res.toJSON())
    return result
}

export async function getShopDesign({shopId, page}) {
    if (shopId) {
        /*根据shopId==>user==>design s*/
        var query_shop = getQuery('shop')
        var shop = await  query_shop.equalTo('objectId', shopId).include('user').first().then(res => res.toJSON())
        var user = object_w('user', shop.user.objectId)
        var query_design = getQuery('design')
        query_design.equalTo('user', user)
        var result = await  query_design.limit(page.limit).skip(page.offset).find().then(res => res.map(item => item.toJSON()))
        return result
    }

}